package problema069;

public class TotientMaximum {
	
	static boolean[] isPrime;
	static int maxVal = 0;
	static double max = 0;
	
	public static void main(String[] args){
		System.out.println(maxTotient());
	}
	
	public static int maxTotient(){
		sieveOfEratosthenes(1000000);
		int res = 1;
		for(int i = 1; i < 1000000; i++){
			if(isPrime[i]){
				if(res * i > 1000000)return res;
				res *= i;
			}
		}
		return 0;
		/*double act = 0;
		for(int i = 2; i < 1000000; i++){
			System.out.println(i);
			if(isPrime[i]) continue;
			act = totient(i);
			if(act > max){
				maxVal = i;
				max = act;
			}
		}
		*/
	}
	
	public static double totient(int n){
		double res = (double) n, act = 0;
		for(double i = 1; i < n; i++){
			if(isPrime[(int)i] && (n % i) == 0){
				act = (double) 1 - (double)(1 / i);
				res *= act;
			}
		}
		return res;
	}
	
	public static void sieveOfEratosthenes(int n){
	     isPrime = new boolean[n + 1];
	     for (int i = 2; i <= n; i++) {
	         isPrime[i] = true;
	     }
	     for (int i = 2; i*i <= n; i++) {
	         if (isPrime[i]) {
	             for (int j = i; i*j <= n; j++) {
	                 isPrime[i*j] = false;
	             }
	         }
	     }
	 }

}
